﻿using Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFCouse
{
    /// <summary>
    /// ComboBoxWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ComboBoxWindow : Window
    {
        public ComboBoxWindow()
        {
            InitializeComponent();
           
        }



        private DataTable GetClasses()
        {
            string sql = "select ClassId,ClassName from ClassInfos where GradeId=4";
            return SqlHelper.GetDataTable(sql, 1);
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
          //  object selectedValue = cboList.SelectedValue;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //  cboList.SelectedValue = item1;
            //cboList.SelectedIndex = 0;//选择项  


            //DataTable dt = GetClasses();

            //数据绑定
            //cboList2.ItemsSource = dt.AsDataView();
            //还可以在Xaml里设置
            //cboList2.DisplayMemberPath = "ClassName";
            //cboList2.SelectedValuePath = "ClassId";
            // cboList2.DataContext = dt.AsDataView();

            //List<ClassInfo> list = new List<ClassInfo>();
            //foreach (DataRow row in dt.Rows)
            //{
            //    ClassInfo info = new ClassInfo()
            //    {
            //        ClassId =int.Parse(row["ClassId"].ToString()),
            //        ClassName = row["ClassName"].ToString()
            //    };
            //    list.Add(info);
            //   // cboList2.Items.Add(info);
            //}
            //cboList2.DataContext = list;
        }

        private void cboList2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // object item = cboList2.SelectedItem;//DataRowView
            //string name = (item as DataRowView).Row["ClassName"].ToString();
            object obj = cboList2.SelectedValue;//班级编号值
        }

     
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            cboList2.Items.RemoveAt(2);//无法修改  绑定的数据源，不能直接删除
        }

        
    }
    public class ClassInfo
    {
        public int ClassId { get; set; }
        public string ClassName { get; set; }
    }
}
